package com.csi.juegoweb.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.csi.juegoweb.dao.NivelDAO;
import com.csi.juegoweb.domain.Nivel;

@Repository("nivelDao")
public class NivelDAOJdbc implements NivelDAO {
	
	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Override
	public List<Nivel> getNiveles() {
		// TODO Auto-generated method stub
		return jdbcTemplate.query("select " +
				"Co_Nivel,"+
				"Co_descripcion, " +
				"Nu_Monto, " +
				"Nu_cant_donan " +
				"from nivel", 
				new BeanPropertyRowMapper<Nivel>(Nivel.class));
	}

	@Override
	public void eliminar(Integer conivel) {
		// TODO Auto-generated method stub
		jdbcTemplate.update(" delete from nivel where co_nivel = ?", conivel);

	}

	@Override
	public void crear(Nivel nivel) {
		// TODO Auto-generated method stub
		jdbcTemplate.update("insert into nivel " +
				"(Co_descripcion, " +
				"Nu_Monto, " +
				"Nu_cant_donan )" +
				"values (?,?,?)", 
				nivel.getCoDescripcion(),
				nivel.getNuMonto(),
				nivel.getNuCantDonan());

	}

}
